<?php

use yii\db\Migration;

class workflow extends Migration
{
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%workflow}}', [
            'wf_id' => $this->primaryKey()->comment('流程id'),
            'wf_name' => $this->string(50)->notNull()->unique()->comment('流程名称'),
            'wf_filename' => $this->text()->comment('流程xml描述'),
            'wf_layout' => $this->text()->comment('流程json位置描述'),
            'wf_version' => $this->string(50)->comment('版本'),
            'wf_handle' => $this->string(100)->notNull()->unique()->comment('无用'),
            'wf_superior' => $this->string(50)->notNull()->unique()->comment('无用'),
            'created_at' => $this->integer(11)->unsigned()->notNull(),
            'updated_at' => $this->integer(11)->unsigned()->notNull(),
        ], $tableOptions);

        $this->createTable('{{%workflow_xmllog}}', [
            'id' => $this->primaryKey()->comment('主键id'),
            'wf_id' => $this->integer(11)->comment('流程id'),
            'wf_name' => $this->string(50)->notNull()->unique()->comment('流程名称'),
            'wf_filename' => $this->text()->comment('流程xml描述'),
            'wf_layout' => $this->text()->comment('流程json位置描述'),
            'wf_version' => $this->string(50)->comment('版本'),
            'created_at' => $this->integer(11)->unsigned()->notNull(),
            'updated_at' => $this->integer(11)->unsigned()->notNull(),
        ], $tableOptions);
    }

    public function down()
    {
        $this->dropTable('{{%workflow}}');
        $this->dropTable('{{%workflow_xmllog}}');
    }
}
